import axios from "axios"
import qs from "qs"

let baseUrl = null;

//生产模式
if (process.env.NODE_ENV === 'production') {
  baseUrl = 'http://localhost:8081/api/';
}

//开发模式
if (process.env.NODE_ENV === 'development') {
  baseUrl = 'http://localhost:8081/api/';
}


axios.defaults.baseURL = baseUrl
axios.defaults.timeout = 1000 * 30
axios.defaults.withCredentials = true
axios.defaults.baseURL = '/api'
axios.defaults.headers.post['Content-Type'] = 'application/json';
axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded';


axios.interceptors.request.use(function (config) {

  //设置token
  var token = localStorage.getItem("token");
  if (token) {
    config.headers.Authorization = token
  }

  config.data = qs.stringify(config.data);  //qs处理
  return config;
}, function (error) {
  return Promise.reject(error);
});
export default axios
